package 华为OD机试B卷复用题.基础题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ30_磁盘容量排序 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试B卷复用题/基础题/input/30.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    static void Solution(Scanner in) {
        // 每次遍历到字母就用一次 substr，不难。
        String now = "2G4M";
        int index = 0;
        int nowToMB = 0;
        for (int i = 0; i < now.length(); i++) {
            if (now.charAt(i) == 'M') {
                int num = Integer.parseInt(now.substring(index, i));
                nowToMB += num;
                index = i + 1;
            }
            if (now.charAt(i) == 'G') {
                int num = Integer.parseInt(now.substring(index, i));
                nowToMB += 1024 * num;
                index = i + 1;
            }
            if (now.charAt(i) == 'T') {
                int num = Integer.parseInt(now.substring(index, i));
                nowToMB += 1024 * 1024 * num;
                index = i + 1;
            }
        }
        System.out.println(nowToMB);
    }
}
